/*
  The a.out.c file implements some a.out files management functions
*/

#include <types.h>
#include <klib.h>
#include <scheduler.h>
#include <a.out.h>

dword_t aout_get_text_base(struct exec *aout_header)
{
  dword_t addr;

  addr=N_TXTADDR(*aout_header);

  return addr;
}

dword_t aout_get_data_base(struct exec *aout_header)
{
  dword_t addr,mod;

  addr=aout_get_text_base(aout_header);
  addr+=aout_header->a_text;

  // get lower 12 bits
  mod = addr & 0x00000FFF;
  // mask lower 12 bits
  addr&=0xFFFFF000;
  // increment 1 page if we're not page aligned
  if (mod)
    addr+=0x1000;

  return addr;
}

dword_t aout_get_bss_base(struct exec *aout_header)
{
  dword_t addr,mod;

  addr=aout_get_data_base(aout_header);
  addr+=aout_header->a_data;

  // get lower 12 bits
  mod = addr & 0x00000FFF;
  // mask lower 12 bits
  addr&=0xFFFFF000;
  // increment 1 page if we're not page aligned
  if (mod)
    addr+=0x1000;

  return addr;
}

dword_t aout_get_entry_point(struct exec *aout_header)
{
  dword_t addr;
  
  addr=aout_get_text_base(aout_header)+sizeof(struct exec);

  return addr;
}

